package com.example.yichuangyun.config;

import com.example.yichuangyun.model.UserInfoModel;
import com.example.yichuangyun.utils.sharedpreference.SPUtil;

/**
 * 用户信息管理
 */
public class UserManager {
    private static UserManager INSTANCE = null;

    public static UserManager getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new UserManager();
        }
        return INSTANCE;
    }

    public void saveUserInfo(UserInfoModel userInfoModel) {
        setPhone(userInfoModel.getPhone());
        setId(userInfoModel.getId());
        setToken(userInfoModel.getBearer());
        setDataVisualRegion(userInfoModel.getDataVisualRegion());
        setJobNumber(userInfoModel.getJobNumber());
        setYcyCampaign(userInfoModel.getYcyCampaign());
    }

    public void clearUserInfo() {
        setLogin(false);
        setId("");
        setToken("");
        setPhone("");
        setDataVisualRegion(null);
        setJobNumber("");
        setYcyCampaign(-1);
    }

    public boolean isLogin() {
        return SPUtil.getBoolean("isLogin", false);
    }

    public void setLogin(boolean isLogin) {
        SPUtil.put("isLogin", isLogin);
    }

    public void setPhone(String Phone) {
        SPUtil.put("phone", Phone);
    }

    public String getPhone() {
        return SPUtil.getString("phone", "");
    }

    public void setToken(String token) {
        SPUtil.put("token", token);
    }

    public String getToken() {
        return SPUtil.getString("token", "");
    }

    /**
     * @param dataVisualRegion 数据查看范围: 0=非创发，1=创发，2=全部
     */
    public void setDataVisualRegion(Integer dataVisualRegion) {
        SPUtil.put("dataVisualRegion", dataVisualRegion);
    }

    public int getDataVisualRegion() {
        return SPUtil.getInt("dataVisualRegion", -1);
    }

    public void setId(String id) {
        SPUtil.put("id", id);
    }

    public String getId() {
        return SPUtil.getString("id", "");
    }

    public void setJobNumber(String jobNumber) {
        SPUtil.put("jobNumber", jobNumber);
    }

    public String getJobNumber() {
        return SPUtil.getString("jobNumber", "");
    }

    public void setYcyCampaign(int ycyCampaign) {
        SPUtil.put("ycyCampaign", ycyCampaign);
    }

    public int getYcyCampaign() {
        return SPUtil.getInt("ycyCampaign", -1);
    }

    public void setThumbAvatar(String thumbAvatar) {
        SPUtil.put("thumbAvatar", thumbAvatar);
    }

    public String getThumbAvatar() {
        return SPUtil.getString("thumbAvatar", "");
    }

}

